package com.zfy.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zfy.tingshu.album.mapper.AlbumAttributeValueMapper;
import com.zfy.tingshu.album.mapper.AlbumInfoMapper;
import com.zfy.tingshu.album.service.AlbumInfoService;
import com.zfy.tingshu.common.constant.RedisConstant;
import com.zfy.tingshu.common.login.TsLogin;
import com.zfy.tingshu.common.result.Result;
import com.zfy.tingshu.common.util.AuthContextHolder;
import com.zfy.tingshu.model.album.AlbumAttributeValue;
import com.zfy.tingshu.model.album.AlbumInfo;
import com.zfy.tingshu.vo.album.AlbumInfoVo;
import com.zfy.tingshu.vo.album.AlbumListVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zfy.tingshu.vo.album.AlbumStatVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Nullable;
import java.util.List;

@Tag(name = "专辑管理")
@RestController
@RequestMapping("api/album/albumInfo")
@SuppressWarnings({"all"})
public class AlbumInfoApiController {

	@Autowired
	private AlbumInfoService albumInfoService;

	@Autowired
	private RedisTemplate redisTemplate;



	@TsLogin
	@Operation(summary = "获取专辑列表")
	@GetMapping("/findUserAllAlbumList")
	public Result findUserAllAlbumList() {
		//	获取用户Id
		Long userId = null == AuthContextHolder.getUserId() ? 1l : AuthContextHolder.getUserId();
		//	调用服务层方法;
		List<AlbumInfo> albumInfoList = albumInfoService.findUserAllAlbumList(userId);
		//	返回专辑列表
		return Result.ok(albumInfoList);
	}

	@TsLogin
	@Operation(summary = "提交订单")
	@PostMapping("/saveAlbumInfo")
	public Result saveAlbumInfo(@RequestBody AlbumInfoVo albumInfoVo){
		albumInfoService.saveAlbumInfo(albumInfoVo);
		return Result.ok();
	}

	@TsLogin(required = true)
	@Operation(summary = "分页查询")
	@PostMapping("/findUserAlbumPage/{pageNum}/{size}")
	public Result findUserAlbumPage(@PathVariable Integer pageNum,@PathVariable Integer size){
		IPage<AlbumListVo> page = new Page<>(pageNum,size);
		albumInfoService.findUserAlbumPage(page);
		return Result.ok(page);
	}
	@Operation(summary = "修改回显")
	@GetMapping("/getAlbumInfo/{albumId}")
	public Result getAlbumInfo(@PathVariable Long albumId){
		return Result.ok(albumInfoService.getAlbumInfo(albumId));
	}




	@Operation(summary = "保存修改信息")
	@PutMapping("updateAlbumInfo/{albumId}")
	public Result updateAlbumInfo(@PathVariable Long albumId,@RequestBody AlbumInfo albumInfo){
		albumInfoService.updateAlbumInfo(albumId,albumInfo);
		  return Result.ok();
	}

	@Operation(summary = "删除信息")
	@DeleteMapping("/removeAlbumInfo/{albumId}")
	public Result deleteAlbumInfo(@PathVariable Long albumId){
		albumInfoService.removeAlbumInfo(albumId);
		return Result.ok();
	}

	@Operation(summary = "根据关键词检索")
	@GetMapping("getAlbumStatVo/{albumId}")
	public Result<AlbumStatVo> getAlbumStatVo(@PathVariable("albumId")Long albumId){
		AlbumStatVo albumStatVo = albumInfoService.getAlbumStatVo(albumId);
		return Result.ok(albumStatVo);

	}

	/**
	 * descriptions:
	 * 1. 根据一级分类Id 查询一级分类对象
	 * 2. 根据一级分类Id查询当前一级分类Id 下对应的集合数据
	 * 3. 根据二级分类Id进行分组获取二级分类对象
	 * 4. 获取二级下对应的三级分类数据
	 * 5. 将数据统一封装到一级分类对象中
	 */










}

